﻿
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyWrite.API.Appicant.Command.Menus;
using B.S.DataBase.MyWrite.API.Appicant.Command.Roles;
using B.S.DataBase.MyWrite.API.Appicant.Command.Users;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyWrite.API.Controllers
{
    /// <summary>
    /// 用户管理--写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        #region 用户管理

        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddUser(AddUserCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> DelUser(DelUserCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> UpdateUser(UpdateUserCommand request)
        {
            return mediator.Send(request);
        }
        #endregion

        #region 角色管理
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddRole(RoleCreateCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> DelRole(RoleDelCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        [HttpPost]
        public Task<APIResult<object>> RoleUpdate(RoleUpdateCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> UserRoleAddRanges(UserRoleCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量删除用户角色关系表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<string>> RemoveUserRole(RemoveUserRoleCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 通过角色ID批量删除关系表
        /// </summary>
        [HttpPost]
        public async Task<APIResult<string>> UserRoleRemoveRange(RemoveRoleIdCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 菜单管理

        /// <summary>
        /// 菜单添加
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> AddMenu(AddMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 菜单修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> UpdateMenu(UpdateMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> DelMenu(DelMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 批量添加角色菜单关系
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> AddRoleMenu(AddRoleMenuCommand request)
        {
            return mediator.Send(request);
        }
       

        #endregion
    }
}
